package com.yl.chainStore.entity.pay

import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableName
import com.yl.chainStore.common.Constants
import com.yl.common.annotation.NoArg
import com.yl.common.getContext
import java.math.BigDecimal
import java.math.RoundingMode

/**
 * <p>
 *   用户账户
 * </p>
 *
 * @author cxw
 * @since 2021-07-30
 */
@NoArg
@TableName("pay_customer_account")
data class PayCustomerAccount(

	/**
	 * 患者
	 */
	@TableField(value = "customer_id")
	var customerId: Long,

	/**
	 * 分院
	 */
	@TableField(value = "sub_company_id")
	var subCompanyId: Long,

	/**
	 * 余额（充值）
	 */
	@TableField("balance")
	var balance: Long = 0,



	/**
	 * 积分
	 */
	@TableField("integral")
	var integral: Long = 0,

	/**
	 * 欠款金额
	 */
	@TableField("amount_owed")
	var amountOwed: Long = 0,

	/**
	 * 公司（备用）
	 */
	@TableField("company_id")
	var companyId: Long = getContext().companyId,

	/**
	 * 馈赠金额
	 */
	@TableField("gifts_of_gold")
	var giftsOfGold:Long = 0
	) {
	@TableField(exist = false)
	var balanceShow: BigDecimal? = null
		get() {
			if (field == null) {
				return BigDecimal(balance.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)
			}
			return field
		}
		set(value) {
			if (value != null) {
				balance = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
				field = value
			}
		}

	@TableField(exist = false)
	var amountOwedShow: BigDecimal? = null
		get() {
			if (field == null) {
				return BigDecimal(amountOwed.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)
			}
			return field
		}
		set(value) {
			if (value != null) {
				amountOwed = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
				field = value
			}
		}

	@TableField(exist = false)
	var giftsOfGoldShow: BigDecimal? = null
		get() {
			if (field == null) {
				return BigDecimal(giftsOfGold.div(Constants.OtherConfig.MONEY_TO_DB_DOUBLE)).setScale(
					2,
					RoundingMode.HALF_UP
				)
			}
			return field
		}
		set(value) {
			if (value != null) {
				giftsOfGold = (value.multiply(BigDecimal(Constants.OtherConfig.MONEY_TO_DB_DOUBLE))).toLong()
				field = value
			}
		}

}
